<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>15.6.DOM-操作元素-样式属性操作</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div></div>
    <script>
        // 1.获取元素
        var div = document.querySelector('div');
        // 2.注册事件 处理程序
        var flag = 0;
        div.onclick = function () {
            // div.style.里面的属性采用驼峰命名法
            if (flag == 0) {
                this.style.width = '250px'
                this.style.height = '250px'
                this.style.backgroundColor = 'purple';
                flag = 1;
            } else {
                this.style.width = '200px'
                this.style.height = '200px'
                this.style.backgroundColor = 'red';
                flag = 0;
            }
        }
    </script>
</body>

</html>